package com.jieao.generator.controller;

import com.jieao.common.core.controller.BaseController;
import com.jieao.common.core.domain.AjaxResult;
import com.jieao.common.core.page.TableDataInfo;
import com.jieao.generator.domain.SmsTemp;
import com.jieao.generator.service.ISmsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短信发送
 */
@Controller
@RequestMapping("/tool/sms")
public class SmsController extends BaseController
{
    private String prefix = "backend/tool/sms";

    @Autowired
    private ISmsService smsService;

    @RequiresPermissions("tool:sms:view")
    @GetMapping()
    public String sms()
    {
        return prefix + "/sms";
    }

    /**
     * 查询模板列表
     */
    @RequiresPermissions("tool:sms:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SmsTemp smsTemp)
    {
        startPage();
        List<SmsTemp> list = smsService.selectSmsTempList(smsTemp);
        return getDataTable(list);
    }

    /**
     * 新增模板页面
     */
    @RequiresPermissions("tool:sms:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存模板
     */
    @RequiresPermissions("tool:sms:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated SmsTemp smsTemp)
    {
        return toAjax(smsService.insertSmsTemp(smsTemp));
    }

    @RequiresPermissions("tool:sms:refresh")
    @GetMapping("/refresh")
    @ResponseBody
    public AjaxResult refresh()
    {
        return smsService.refreshTempStatus();
    }
    /**
     * 批量删除模板
     **/
    @RequiresPermissions("tool:sms:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(smsService.deleteSmsTempByIds(ids));
    }


}
